import { Edge, Node } from '@antv/x6'
import { defineStore } from 'pinia'

export const useCanvasParameterStore = defineStore('canvasParameter', {
  state: () => ({
    //========================================= 画布 ================================================================================================

    //当前画布左上角的坐标
    canvasPosition: { x: 0, y: 0 },
    //画布缩放比例
    canvasScale: 1,
    //是否开启画布节点交互
    isCanvasNodeInteractive: true,
    //画布标尺的显示与隐藏
    isCanvasRuler: true,
    //是否出发画布的框选监听事件
    isCanvasSelect: true,
    //画布模式
    canvasMode: {
      current: 'select' as 'select' | 'drag',
      before: 'select' as 'select' | 'drag'
    },
    //是否开启图形变换
    isGraphTransform: false,

    //========================================= 节点 ================================================================================================

    //当前选中的节点
    selectedNode: null as Node | null,
    //当前复制的节点列表
    copyNodeList: [] as string[],
    //是否开启自由区域节点编辑功能
    isFreeAreaEdit: false,
    //是否开启节点尺寸编辑功能
    isNodeSizeEdit: false,

    //========================================= 边 ================================================================================================

    //当前选中的边
    selectedEdge: null as Edge | null,
    //是否开启连接边编辑功能
    isEdgeEdit: false,
    //添加连线的Add节点
    addEdgeNode: {
      source: null as Node | null,
      target: null as Node | null
    },
    //边是否可以被移动
    isEdgeMovable: false,

    //========================================= 快捷键 ================================================================================================

    //shift键是否被按下
    isShiftDown: false,
    //ctrl键是否被按下
    isCtrlDown: false,
    //shift+e键是否被按下
    isShiftEDown: false,
    //shift+r键是否被按下
    isShiftRDown: false
  }),
  actions: {
    //设置选中的节点
    setSelectedNode(node: Node | null) {
      this.selectedNode = node
    }
  }
})
